#ifndef _HTTPPACKET_H_
#define _HTTPPACKET_H_
#include "UrlCoder.h"
#include "StringCoder.h"
#include "../json/json.h"
#include<string>
#include<map>
#include <sstream>
using namespace std;

class HttpRequestPacket
{
private:
	string host;
	UINT port;
	string method;
	string httpVersion;
	string requestFile;
	string agent;
	string referer;
	map<string,string> cookie;
public:
	HttpRequestPacket();
	void SetHost(const string& host);
	void SetPort(UINT port);
	void SetMethod(const string& method);
	void SetHttpVersion(const string& version);
	void SetRequestFile(const string& file);
	void SetAgent(const string& agent);
	void SetReferer(const string& refer);
	virtual string ToRequestString() const;
	void ClearCookie();
	void AddCookie(const string& key,const string& val);
	string GetHost() const;
	UINT GetPort() const;
};

class HttpPostPacket : public HttpRequestPacket
{
private:
	map<string,wstring> data;
public:
	HttpPostPacket();
	virtual string ToRequestString() const;
	void ClearData();
	void AddData(const string& key,const wstring& val);
};
class HttpResponsePacket{
private:
	int resCode;
	int contentLen;
	string contentType;
	map<string,string> cookies;
protected:
	bool parseError;
	wstring errorStr;
	const string responseTxt;
public:
	HttpResponsePacket(const string& responseStr);
	int ResponseCode() const;
	int ContentLength() const;
	string ContentType() const;
	map<string,string> GetCookie() const;
	bool ParseError() const;
	wstring ErrorString() const;
	string GetVal(const string& key);
};
class HttpResponseJsonPacket : public HttpResponsePacket
{
private:
	Json::Value content;
public:
	HttpResponseJsonPacket(const string& responseStr);
	Json::Value GetContent() const;
};
#endif